<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no,viewport-fit=cover">
		<title></title>
		<link rel="stylesheet" href="../../css/mui.min.css">
		<link rel="stylesheet" href="../../css/app.css">
		<style>
			.submit{width: 6rem;height: 0.68rem;background: #117afd;font-size: 0.3rem;color: #fff;border: none;outline: none;border-radius: 0.1rem; margin: .5rem auto;}
			.oldpwd{border: none !important;border-bottom: 1px solid #eeeeee !important;border-radius: 0 !important;padding-left: 1.35rem !important;}
			.mui-input-row{width: 7.5rem;height: 1.06rem;}
			.mui-input-row input{margin: 0 !important; width: 100% !important;height: 100% !important;font-size: 0.3rem;}
			.mui-input-row img{width: 0.3rem;height: 0.36rem;position: absolute;top: 0.33rem;left: 0.72rem;}
			.mui-icon-eye{top: 0.30rem !important;font-size: 0.4rem !important;right: 0.3rem !important;color: #d6d6d6 !important;}
			.mui-active{color: #007aff !important;}
			.mui-icon-clear{top: 0.30rem !important;font-size: 0.4rem !important;right: 1.35rem !important;color: #d6d6d6 !important;}
			input::-webkit-input-placeholder {font-size:0.3rem;color: #cccccc;} 
		</style>
	</head>
	<body>
		<div class="mui-input-row">
			<img src="../../images/menu/pwd.png" alt="" />
        	<input type="password" id="oldpwd" class="mui-input-password mui-input-clear oldpwd" placeholder="请输入原密码">
    	</div>
    	<div class="mui-input-row newpwd">
			<img src="../../images/menu/pwd.png" alt="" />
        	<input type="password" id="newpwd" class="mui-input-password mui-input-clear oldpwd" placeholder="请输入新密码">
    	</div>
    	<div class="mui-input-row surepwd">
			<img src="../../images/menu/pwd.png" alt="" />
        	<input type="password" id="confirmpwd" class="mui-input-password mui-input-clear oldpwd" placeholder="请输入确认密码">
    	</div>
		<button class="submit" id="submitInfo">提交</button>
	</body>
	<script src="../../js/mui.min.js"></script>
	<script src="../../js/common.js"></script>
	<script src="../../js/app.js"></script>
	<script src="../../js/md5.min.js"></script>
	<script>		
		document.getElementById('submitInfo').addEventListener('tap', function() {
				var nowpwd = document.getElementById("oldpwd").value;
				var newpwd = document.getElementById("newpwd").value;
				var confirmpwd = document.getElementById("confirmpwd").value;
				
				if(nowpwd==null || nowpwd==""){
					mui.toast("请输入原密码");
					return false;
				}else{
					if(!checkPwdLength(nowpwd)){
						return false;
					}
				}
				
				if(newpwd==null || newpwd==""){
					mui.toast("请输入新密码");
					return false;
				}else{
					if(!checkPwdLength(newpwd)){
						return false;
					}
				}
				
				if(confirmpwd==null || confirmpwd==""){
					mui.toast("请输入确认密码");
					return false;
				}
				
				if(checkPassword(newpwd,confirmpwd)){
                   	var param = 'userId=' +getUserId()+'&&nowPwd='+ md5(nowpwd)+'&&newPwd='+md5(newpwd);			
					utils.ajax('appHttpService/updatePassword.do', function(data) {
						data = JSON.parse(data);
						if(data.state == '0' || data.state  == 0){//密码修改成功后，注销当前信息，跳转到登录界面
							mui.toast(data.msg);
							setTimeout(function() {//1秒后跳转到登录界面
					         	removeState();//移除登录状态
								//移除头像 如果有
								localStorage.removeItem('headDir');
								utils.showWaiting();
								var app_index = plus.webview.getLaunchWebview();
								mui.fire(app_index,'loginRefresh',{'flag':3});	
								plus.webview.close("../setting/setting.html");
								mui.back();//关闭当前页面
				            }, 1000);
						}else if(data.state == '-1' || data.state == -1){//密码修改失败
							mui.toast(data.msg);
						}
					}, param);
				}
			})
		
			//新密码和确认密码比较
			function checkPassword(newpwd,confirmpwd){
					if(newpwd!=confirmpwd){
						mui.toast("新密码和确认密码不一致!");
						return false;
					}
					return true;
			}
			
			/**
			 * 验证密码长度
			 * @param {Object} pwd 密码
			 */
			function checkPwdLength(pwd){
				if(pwd.length<6 ){
					mui.toast("密码长度不得小于6位!");
					return false;
				}
				
				if(pwd.length>15 ){
					mui.toast("密码长度不得大于15位!");
					return false;
				}
				
				return true;
			}
	</script>
</html>